import { getArticleCommentList } from '@/services';
import { ICommentItem } from '@/types';


import { Effect, Reducer } from 'umi';

export interface CommentModelState {
    CommentItem:ICommentItem[]
}

export interface CommentModelType {
  namespace: 'comment';
  state: CommentModelState;
  effects: {

    getArticleCommentList: Effect;
  };
  reducers: {
    save: Reducer<CommentModelState>;
  };

}

const PageModel: CommentModelType = {
  namespace: 'comment',
  state: {
    CommentItem: []
  },
  //副作用
  effects: {
    *getArticleCommentList({ payload }, { call, put }) {
      const result = yield call(getArticleCommentList,payload)
      
      if (result.data) {
        yield put({
          type: 'save',
          payload: {
            CommentItem: result.data[0]
          }
        })
      }
    }
  },
  //同步修改state的操作
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },

  },

};

export default PageModel;